package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.search.AlbumInfoDetailVo;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexSearchVo;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {



    @Autowired
    private SearchService searchService;

    @Operation(summary = "获取排行榜列表")
    @GetMapping("findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable(value = "category1Id") Long category1Id,
                                                          @PathVariable(value = "dimension") String dimension) {
        List<AlbumInfoIndexVo> albumInfoIndexVoList = searchService.findRankingList(category1Id, dimension);
        return Result.ok(albumInfoIndexVoList);
    }

    @Operation(summary = "上架专辑")
    @GetMapping("upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable(value = "albumId") Long albumId) {
        searchService.upperAlbum(albumId);
        return Result.ok(null);
    }

    @Operation(summary = "下架专辑")
    @GetMapping("lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable(value = "albumId") Long albumId) {
        searchService.lowerAlbum(albumId);
        return Result.ok(null);
    }

    @Operation(summary = "批量上架")
    @GetMapping("batchUpperAblum")
    public Result batchUpperAblum() {
        for (long i = 1; i <= 1500; i++) {
            searchService.upperAlbum(i);
        }
        return Result.ok(null);
    }

    @Operation(summary = "专辑列表搜索")
    @PostMapping
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery) {
        return Result.ok(searchService.search(albumIndexQuery));
    }


    @Operation(summary = "获取频道页数据")
    @GetMapping("channel/{category1Id}")
    public Result<List<AlbumInfoIndexSearchVo>> channel(@PathVariable(value = "category1Id") Long category1Id) {
        List<AlbumInfoIndexSearchVo> albumInfoIndexSearchVoList = searchService.channel(category1Id);
        return Result.ok(albumInfoIndexSearchVoList);
    }

    @Operation(summary = "关键字自动补全")
    @GetMapping("completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable(value = "keyword") String keyword) {
        List<String> suggestList = searchService.completeSuggest(keyword);
        return Result.ok(suggestList);
    }


    @Operation(summary = "更新排行榜")
    @GetMapping("/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking() {
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }
}

